package org.hfy.calc;

import org.hfy.collections.helper.Production;
import org.hfy.collections.helper.Symbol;

import java.util.*;

/**
 * @Description:
 * @Author: Takagi
 * @date: 2023/5/28
 */
public class LLTable {
    public Map<Symbol, LLState> stateMap;

    public LLTable() {
        stateMap = new HashMap<>();
    }

    public LLState get(Symbol name) {
        LLState res = stateMap.get(name);
        if (res == null) {
            return new LLState();
        }
        return res;
    }

    public void add(Symbol symbol, LLState state) {
        stateMap.put(symbol, state);
    }

    public void showTable() {
        stateMap.forEach((symbol, state) -> System.out.printf("[%s]\n%s\n\n", symbol, state));
    }

    public void showTable(List<Production> order) {
        for (Production production : order) {
            LLState state = stateMap.get(production.left);
            Symbol symbol = production.left;
            System.out.printf("[%s]\n%s\n\n", symbol, state);
        }
    }
}
